(function(){if(window["BXPostFormTags"])return;var e={selector:{},mentionParams:{}};window.BXPostFormTags=function(e,t){this.popup=null;this.formID=e;this.buttonID=t;this.sharpButton=null;this.addNewLink=null;this.tagsArea=null;this.hiddenField=null;this.popupContent=null;BX.ready(BX.proxy(this.init,this))};window.BXPostFormTags.prototype.init=function(){this.sharpButton=BX(this.buttonID);this.addNewLink=BX("post-tags-add-new-"+this.formID);this.tagsArea=BX("post-tags-block-"+this.formID);this.tagsContainer=BX("post-tags-container-"+this.formID);this.hiddenField=BX("post-tags-hidden-"+this.formID);this.popupContent=BX("post-tags-popup-content-"+this.formID);this.popupInput=BX.findChild(this.popupContent,{tag:"input"});var e=BX.findChildren(this.tagsContainer,{className:"feed-add-post-del-but"},true);for(var t=0,i=e.length;t<i;t++){BX.bind(e[t],"click",BX.proxy(this.onTagDelete,{obj:this,tagBox:e[t].parentNode,tagValue:e[t].parentNode.getAttribute("data-tag")}))}BX.bind(this.sharpButton,"click",BX.proxy(this.onButtonClick,this));BX.bind(this.addNewLink,"click",BX.proxy(this.onAddNewClick,this))};window.BXPostFormTags.prototype.onTagDelete=function(){BX.remove(this.tagBox);this.obj.hiddenField.value=this.obj.hiddenField.value.replace(this.tagValue+",","").replace("  "," ")};window.BXPostFormTags.prototype.show=function(){if(this.popup===null){this.popup=new BX.PopupWindow("bx-post-tag-popup",this.addNewLink,{content:this.popupContent,lightShadow:false,offsetTop:8,offsetLeft:10,autoHide:true,angle:true,closeByEsc:true,zIndex:-840,buttons:[new BX.PopupWindowButton({text:BX.message("TAG_ADD"),events:{click:BX.proxy(this.onTagAdd,this)}})]});BX.bind(this.popupInput,"keydown",BX.proxy(this.onKeyPress,this));BX.bind(this.popupInput,"keyup",BX.proxy(this.onKeyPress,this))}this.popup.show();BX.focus(this.popupInput)};window.BXPostFormTags.prototype.addTag=function(e){var t=BX.type.isNotEmptyString(e)?e.split(","):this.popupInput.value.split(",");var i=[];for(var n=0;n<t.length;n++){var o=BX.util.trim(t[n]);if(o.length>0){var r=this.hiddenField.value.split(",");if(!BX.util.in_array(o,r)){var s;var a=BX.create("span",{children:[s=BX.create("span",{attrs:{class:"feed-add-post-del-but"}})],attrs:{class:"feed-add-post-tags"}});a.insertBefore(document.createTextNode(o),s);this.tagsContainer.insertBefore(a,this.addNewLink);BX.bind(s,"click",BX.proxy(this.onTagDelete,{obj:this,tagBox:a,tagValue:o}));this.hiddenField.value+=o+",";i.push(o)}}}return i};window.BXPostFormTags.prototype.onTagAdd=function(){this.addTag();this.popupInput.value="";this.popup.close()};window.BXPostFormTags.prototype.onAddNewClick=function(e){e=e||window.event;this.show();BX.PreventDefault(e)};window.BXPostFormTags.prototype.onButtonClick=function(e){e=e||window.event;BX.show(this.tagsArea);this.show();BX.PreventDefault(e)};window.BXPostFormTags.prototype.onKeyPress=function(e){e=e||window.event;var t=e.keyCode?e.keyCode:e.which?e.which:null;if(t==13){setTimeout(BX.proxy(this.onTagAdd,this),0)}};window.BXPostFormImportant=function(e,t,i){if(i){this.formID=e;this.buttonID=t;this.inputName=i;this.fireButton=null;this.activeBlock=null;this.hiddenField=null;BX.ready(BX.proxy(this.init,this))}return false};window.BXPostFormImportant.prototype.init=function(){this.fireButton=BX(this.buttonID);this.activeBlock=BX(this.buttonID+"-active");var e=BX(this.formID);if(e){this.hiddenField=e[this.inputName];if(this.hiddenField&&this.hiddenField.value==1){this.showActive()}}BX.bind(this.fireButton,"click",BX.proxy((function(e){e=e||window.event;this.showActive();BX.PreventDefault(e)}),this));BX.bind(this.activeBlock,"click",BX.proxy((function(e){e=e||window.event;this.hideActive();BX.PreventDefault(e)}),this))};window.BXPostFormImportant.prototype.showActive=function(e){BX.hide(this.fireButton);BX.show(this.activeBlock,"inline-block");if(this.hiddenField){this.hiddenField.value=1}return false};window.BXPostFormImportant.prototype.hideActive=function(e){BX.hide(this.activeBlock);BX.show(this.fireButton,"inline-block");if(this.hiddenField){this.hiddenField.value=0}return false};var t=null;window.MPFbuttonShowWait=function(e){if(e&&!BX.type.isElementNode(e)){e=null}e=e||this;e=e?e.tagName=="A"?e:e.parentNode:e;if(e){BX.addClass(e,"ui-btn-clock");t=e;BX.defer((function(){e.disabled=true}))()}};var i={listen:false,plus:false,text:"",bSearch:false,node:null,mode:null};BX.addCustomEvent(window,"onInitialized",(function(e){if(e&&e.eventNode){BX.onCustomEvent(e.eventNode,"OnClickCancel",(function(){i.node=null}))}}));BX.addCustomEvent(window,"BX.MPF.MentionSelector:open",(function(t){var i=BX.Type.isStringFilled(t.formId)?t.formId:"";if(!BX.Type.isStringFilled(i)||BX.Type.isUndefined(e.mentionParams[i])){return}var n=BX.Type.isDomNode(t.bindNode)?t.bindNode:null;var o=BX.type.isNotEmptyObject(t.bindPosition)?t.bindPosition:null;var r=window.MPFgetSelectorId("bx-mention-"+i+"-id")+(n?"-withsearch":"");var s=BX.UI.EntitySelector.Dialog.getById(r);if(!s){window.MPFcreateSelectorDialog({formId:i,selectorId:r,enableSearch:!!n,params:e.mentionParams[i]});s=BX.UI.EntitySelector.Dialog.getById(r)}if(!s){return}s.deselectAll();s.search("");s.show();var a={};if(BX.Type.isDomNode(n)){s.focusSearch();s.popup.setBindElement(n);a.position="top"}else if(BX.type.isNotEmptyObject(o)){o.top-=5;s.popup.setBindElement(o)}s.popup.adjustPosition(a)}));window.onKeyDownHandler=function(e,t,o){var r=e.keyCode;if(!window["BXfpdStopMent"+o]){return true}var s=window.MPFgetSelectorId("bx-mention-"+o+"-id");if(r===t.KEY_CODES["backspace"]&&i.node){var a=BX.util.trim(t.util.GetTextContent(i.node));if(a==="+"||a==="@"||i.mode=="button"&&a.length==1){window["BXfpdStopMent"+o]()}else if(i.mode=="button"&&a.length==1){window["BXfpdStopMent"+o]()}}if(BX.util.in_array(r,[107,187])||(e.shiftKey||e.modifiers>3)&&BX.util.in_array(r,[50,43,61])||e.altKey&&BX.util.in_array(r,[76])||e.altKey&&e.ctrlKey&&BX.util.in_array(r,[81])&&e.key==="@"||e.altKey&&BX.util.in_array(r,[71,81])&&e.key==="@"||e.altKey&&BX.util.in_array(r,[50])&&e.key==="@"||BX.Type.isFunction(e.getModifierState)&&!!e.getModifierState("AltGraph")&&BX.util.in_array(r,[81,50,48])&&!BX.Type.isUndefined(e.key)&&e.key==="@"||BX.util.in_array(r,[192])&&e.key==="@"){setTimeout((function(){var e=t.selection.GetRange();var r=t.GetIframeDoc();var a=e?e.endContainer.textContent:"";var d=a?a.slice(e.endOffset-1,e.endOffset):"";var l=a?a.slice(e.endOffset-2,e.endOffset-1):"";if((d=="@"||d=="+")&&(!l||BX.util.in_array(l,["+","@",",","("])||l.length==1&&BX.util.trim(l)==="")){i.listen=true;i.listenFlag=true;i.text="";i.leaveContent=true;i.mode="plus";e.setStart(e.endContainer,e.endOffset-1);e.setEnd(e.endContainer,e.endOffset);t.selection.SetSelection(e);i.node=BX.create("SPAN",{props:{id:"bx-mention-node"}},r);t.selection.Surround(i.node,e);e.setStart(i.node,1);e.setEnd(i.node,1);t.selection.SetSelection(e);if(BX.Type.isStringFilled(s)){BX.onCustomEvent(window,"BX.MPF.MentionSelector:open",[{formId:o,bindPosition:n(i.node,t)}])}}}),10)}if(i.listen){var d=null;var l=BX.Type.isStringFilled(s)?BX.UI.EntitySelector.Dialog.getById(s):null;if(l&&l.getActiveTab()){d=l.getActiveTab().getId()}var p=null;switch(r){case t.KEY_CODES.enter:p="Enter";break;case 9:p="Tab";break;case t.KEY_CODES.up:p="ArrowUp";break;case t.KEY_CODES.down:p="ArrowDown";break;case t.KEY_CODES.left:if(d==="departments"){p="ArrowLeft"}break;case t.KEY_CODES.right:if(d==="departments"){p="ArrowRight"}break}if(p){var u=new KeyboardEvent("keydown",{key:p,keyCode:r,bubbles:true,cancelable:true,view:window});if(!document.dispatchEvent(u)){t.iframeKeyDownPreventDefault=true;e.stopPropagation();e.preventDefault()}}}if(!i.listen&&i.listenFlag&&r===t.KEY_CODES["enter"]){var f=t.selection.GetRange();if(f.collapsed){var c=f.endContainer;var m=t.GetIframeDoc();if(c){if(c.className!=="bxhtmled-metion"){c=BX.findParent(c,(function(e){return e.className=="bxhtmled-metion"}),m.body)}if(c&&c.className=="bxhtmled-metion"){t.selection.SetAfter(c)}}}}};window.onKeyUpHandler=function(e,t,n){var o=e.keyCode;var r;var s;if(!window["BXfpdStopMent"+n]){return true}if(i.listen===true){if(o==t.KEY_CODES.escape){var a=new KeyboardEvent("keyup",{key:"Escape",keyCode:o,bubbles:true,cancelable:true,view:window});if(!document.dispatchEvent(a)){e.stopPropagation();e.preventDefault()}window["BXfpdStopMent"+n]()}else if(o!==t.KEY_CODES.enter&&o!==t.KEY_CODES.left&&o!==t.KEY_CODES.right&&o!==t.KEY_CODES.up&&o!==t.KEY_CODES.down){if(BX(i.node)){s=BX.util.trim(t.util.GetTextContent(i.node));var d=s;s=s.replace(/^[\+@]*/,"");i.bSearch=BX.Type.isStringFilled(s);var l=window.MPFgetSelectorId("bx-mention-"+n+"-id");var p=BX.UI.EntitySelector.Dialog.getById(l);if(BX.Type.isStringFilled(s)&&p){p.search(s)}if(i.leaveContent&&i._lastText){if(d===""){window["BXfpdStopMent"+n]()}else if(d!==""&&s===""){i.bSearch=false;if(p){p.search("")}}}i.lastText=s;i._lastText=d}else{window["BXfpdStopMent"+n]()}}}else{if(!e.shiftKey&&(o===t.KEY_CODES["space"]||o===t.KEY_CODES["escape"]||o===188||o===190)){r=t.selection.GetRange();if(r.collapsed){var u=r.endContainer;var f=t.GetIframeDoc();if(u){if(u.className!=="bxhtmled-metion"){u=BX.findParent(u,(function(e){return e.className=="bxhtmled-metion"}),f.body)}if(u&&u.className=="bxhtmled-metion"){s=t.util.GetTextContent(u);var c=s.match(/[\s\.\,]$/);if(c||o===t.KEY_CODES["escape"]){u.innerHTML=s.replace(/[\s\.\,]$/,"");var m=BX.create("SPAN",{html:c||t.INVISIBLE_SPACE},f);t.util.InsertAfter(m,u);t.selection.SetAfter(m)}}}}}}};window.onTextareaKeyDownHandler=function(e,t,n){var o=e.keyCode;if(i.listen&&o==t.KEY_CODES.enter){t.textareaKeyDownPreventDefault=true;e.stopPropagation();e.preventDefault()}};window.onTextareaKeyUpHandler=function(e,t,n){var o=null;var r="";var s=e.keyCode;var a=window.MPFgetSelectorId("bx-mention-"+n+"-id");if(i.listen===true){if(s==27){window["BXfpdStopMent"+n]()}else if(s!==13){r=t.textareaView.GetValue(false);o=t.textareaView.GetCursorPosition();var d="";var l="";if(r.indexOf("+")!==-1||r.indexOf("@")!==-1){var p=r.substr(0,o);var u=Math.max(p.lastIndexOf("+"),p.lastIndexOf("@"));if(u>=0){d=p.substr(u);l=d;d=d.replace(/^[\+@]*/,"");i.bSearch=BX.Type.isStringFilled(d);var f=BX.UI.EntitySelector.Dialog.getById(a);if(BX.Type.isStringFilled(d)&&f){f.search(d)}}}if(i._lastText){if(l===""){window["BXfpdStopMent"+n]()}else if(l!==""&&d===""){i.bSearch=false;if(f){f.search("")}}}i.lastText=d;i._lastText=l}}else{if(s==16){var c=this;this.shiftPressed=true;if(this.shiftTimeout){this.shiftTimeout=clearTimeout(this.shiftTimeout)}this.shiftTimeout=setTimeout((function(){c.shiftPressed=false}),100)}if(s==107||(e.shiftKey||e.modifiers>3||this.shiftPressed)&&BX.util.in_array(s,[187,50,107,43,61])){o=t.textareaView.element.selectionStart;if(o>0){r=t.textareaView.element.value;var m=r.substr(o-1,1);if(m&&(m==="+"||m==="@")){i.listen=true;i.listenFlag=true;i.text="";i.textarea=true;i.bSearch=false;i.mode="plus";BX.onCustomEvent(window,"BX.MPF.MentionSelector:open",[{formId:n,bindPosition:BX.pos(document.getElementById("bx-b-mention-"+n))}])}}}}};var n=function(e,t){var i=BX.pos(e);var n=BX.pos(t.dom.areaCont);var o=BX.GetWindowScrollPos(t.GetIframeDoc());var r=n.top+i.bottom-o.scrollTop+2;var s=n.left+i.right-o.scrollLeft;return{top:r,left:s}};window.BxInsertMention=function(e){var t=e.item;var o=e.type;var r=e.formID;var s=e.editorId;var a=e.bNeedComa;var d=LHEPostForm.getEditor(s);var l;if((o==="user"||o==="project"||o==="department")&&t&&t.entityId>0&&d){if(d.GetViewMode()=="wysiwyg"){var p=d.GetIframeDoc();var u=d.selection.GetRange();var f=BX.create("SPAN",{props:{className:"bxhtmled-metion"},text:BX.util.htmlspecialcharsback(t.name)},p);l=BX.create("SPAN",{html:a?",&nbsp;":"&nbsp;"},p);var c={tag:"postuser",params:{value:t.entityId}};switch(o){case"project":c.projectId=t.entityId;c.projectName=t.name;break;case"department":c.departmentId=t.entityId;c.departmentName=t.name;break;default:c.userId=t.entityId;c.userName=t.name}d.SetBxTag(f,c);if(BX(i.node)&&i.node.parentNode){d.util.ReplaceNode(i.node,f)}else{d.selection.InsertNode(f,u)}if(f&&f.parentNode){var m=BX.findParent(f,{className:"bxhtmled-metion"},p.body);if(m){d.util.InsertAfter(f,m)}}if(f&&f.parentNode){d.util.InsertAfter(l,f);d.selection.SetAfter(l)}}else if(d.GetViewMode()=="code"&&d.bbCode){d.textareaView.Focus();var h=d.textareaView.GetValue(false);var B=d.textareaView.GetCursorPosition();var w=h.substr(0,B);var y=Math.max(w.lastIndexOf("+"),w.lastIndexOf("@"));if(y>=0&&B>y){d.textareaView.SetValue(h.substr(0,y)+h.substr(B));d.textareaView.element.setSelectionRange(y,y)}var X="";switch(o){case"user":X="USER";break;case"project":X="PROJECT";break;case"department":X="DEPARTMENT";break;default:}d.textareaView.WrapWith(false,false,"["+X+"="+t.entityId+"]"+t.name+"[/"+X+"]"+(a?", ":" "))}if(e.fireAddEvent===true){BX.onCustomEvent(window,"onMentionAdd",[t,o])}if(window["BXfpdStopMent"+r]){window["BXfpdStopMent"+r]()}i["text"]="";if(d.GetViewMode()=="wysiwyg"){d.Focus();d.selection.SetAfter(l)}var v=LHEPostForm.getHandler(s);if(v&&v.formEntityType==="task"&&v.editorParams.tasksLimitExceeded){BX.Main.PostFormTasksLimit.showPopup({bindPosition:n(i.node,d)})}}};window.MPFgetSelectorId=function(e){var t=false;var i=BX(e);if(!i){return t}t=i.getAttribute("data-bx-selector-id");return t};window.MPFcreateSelectorDialog=function(e){new BX.UI.EntitySelector.Dialog({targetNode:"mpf-mention-"+e.formId,id:e.selectorId,context:"MENTION",multiple:false,enableSearch:e.enableSearch,clearSearchOnSelect:true,hideOnSelect:true,hideByEsc:true,entities:e.params.entities,height:300,width:400,compactView:true,events:{onShow:function(){window.BXfpdOnDialogOpen()},onHide:function(){window.BXfpdOnDialogClose({editorId:e.params.editorId})},"Item:onSelect":function(t){var i=t.getData().item;if(i){window["BXfpdSelectCallbackMent"+e.formId]({item:{name:i.getTitle(),entityId:i.getId()},entityType:i.getEntityId()})}}}})};window.MPFMentionInit=function(t,n){e.mentionParams[t]=n;if(n.initDestination===true){BX.addCustomEvent("onAutoSaveRestoreDestination",(function(e){if(BX.type.isNotEmptyObject(e)&&BX.type.isNotEmptyObject(e.data)&&BX.type.isNotEmptyString(e.data.DEST_DATA)&&BX.type.isNotEmptyString(e.formId)&&e.formId==t&&BX.UI.EntitySelector){var i=JSON.parse(e.data.DEST_DATA);if(!Array.isArray(i)){return}var n=BX.UI.EntitySelector.Dialog.getById("oPostFormLHE_blogPostForm");if(!BX.type.isNotEmptyObject(n)){return}n.preselectedItems=i;n.setPreselectedItems(i)}}));BX.addCustomEvent(window,"onMentionAdd",(function(e,t){var i=BX.UI.EntitySelector.Dialog.getById("oPostFormLHE_blogPostForm");if(!BX.type.isNotEmptyObject(i)){return}var n="";if(t==="user"){if(e.isExtranet==="Y"){n="extranet"}else if(e.isEmail==="Y"){n="email"}else{n="employee"}}else if(t==="project"){if(e.isExtranet==="Y"){n="extranet"}}i.addItem({avatar:e.avatar,customData:{email:BX.Type.isStringFilled(e.email)?e.email:""},entityId:t,entityType:n,id:e.entityId,title:e.name}).select()}))}window["BXfpdSelectCallbackMent"+t]=function(e){window.BxInsertMention({item:e.item,type:e.entityType.toLowerCase(),formID:t,editorId:n.editorId,fireAddEvent:n.initDestination})};window["BXfpdStopMent"+t]=function(){var e=window.MPFgetSelectorId("bx-mention-"+t+"-id");var i=BX.UI.EntitySelector.Dialog.getById(e);if(i){i.hide()}};if(BX(t)){BX.addCustomEvent(BX(t),"OnUCFormAfterShow",(function(e){if(!BX.type.isNotEmptyObject(e)||!BX.type.isArray(e.id)||!BX.Type.isStringFilled(e.id[0])){return}var t=new RegExp("EVENT_(\\d+)","i");if(!t.test(e.id[0])){return}}))}var o=LHEPostForm.getHandlerByFormId(t);if(o){o.exec()}BX.ready((function(){var e=BX("bx-b-mention-"+t);BX.bind(e,"click",(function(o){if(i.listen!==true){var r=LHEPostForm.getEditor(n.editorId);var s=r.GetIframeDoc();if(r.GetViewMode()=="wysiwyg"&&s){i.listen=true;i.listenFlag=true;i.text="";i.leaveContent=false;i.mode="button";var a=r.selection.GetRange();if(BX(i.node)){BX.remove(BX(i.node))}r.InsertHtml('<span id="bx-mention-node">'+r.INVISIBLE_SPACE+"</span>",a);setTimeout((function(){BX.onCustomEvent(window,"BX.MPF.MentionSelector:open",[{formId:t,bindNode:e}]);i.node=s.getElementById("bx-mention-node");if(i.node){a.setStart(i.node,0);if(i.node.firstChild&&i.node.firstChild.nodeType==3&&i.node.firstChild.nodeValue.length>0){a.setEnd(i.node,1)}else{a.setEnd(i.node,0)}r.selection.SetSelection(a)}r.Focus()}),100)}else if(r.GetViewMode()=="code"){i.listen=true;i.listenFlag=true;i.text="";i.leaveContent=false;i.mode="button";setTimeout((function(){BX.onCustomEvent(window,"BX.MPF.MentionSelector:open",[{formId:t,bindNode:e}])}),100)}BX.onCustomEvent(e,"mentionClick")}}))}))};window.BXfpdOnDialogOpen=function(){i.listen=true;i.listenFlag=true};window.BXfpdOnDialogClose=function(e){i.listen=false;setTimeout((function(){i.listenFlag=false;if(!i.listen){var t=LHEPostForm.getEditor(e.editorId);if(t){t.Focus()}}}),100)};MPFEntitySelector=function(t){this.selector=null;this.inputNode=null;this.messages={};if(!BX.Type.isStringFilled(t.id)){return null}if(e.selector[t.id]){return e.selector[t.id]}e.selector[t.id]=this.init(t)};MPFEntitySelector.prototype.init=function(e){if(!BX.type.isPlainObject(e)){e={}}if(!BX.Type.isStringFilled(e.id)||!BX.Type.isStringFilled(e.tagNodeId)||!BX(e.tagNodeId)){return null}if(BX.Type.isStringFilled(e.inputNodeId)&&BX(e.inputNodeId)){this.inputNode=BX(e.inputNodeId)}if(BX.type.isNotEmptyObject(e.messages)){this.messages=e.messages}this.selector=new BX.UI.EntitySelector.TagSelector({id:e.id,dialogOptions:{id:e.id,context:BX.Type.isStringFilled(e.context)?e.context:null,preselectedItems:BX.type.isArray(e.preselectedItems)?e.preselectedItems:[],events:{"Item:onSelect":function(){this.recalcValue(this.selector.getDialog().getSelectedItems())}.bind(this),"Item:onDeselect":function(){this.recalcValue(this.selector.getDialog().getSelectedItems())}.bind(this)},entities:[{id:"meta-user",options:{"all-users":{title:this.messages.allUsersTitle,allowView:BX.type.isBoolean(e.allowToAll)&&e.allowToAll}}},{id:"user",options:{emailUsers:BX.type.isBoolean(e.allowSearchEmailUsers)?e.allowSearchEmailUsers:false,inviteGuestLink:BX.type.isBoolean(e.allowSearchEmailUsers)?e.allowSearchEmailUsers:false,myEmailUsers:true}},{id:"project",options:{features:{blog:["premoderate_post","moderate_post","write_post","full_post"]}}},{id:"department",options:{selectMode:"usersAndDepartments",allowFlatDepartments:false}}]},addButtonCaption:BX.message("BX_FPD_LINK_1"),addButtonCaptionMore:BX.message("BX_FPD_LINK_2")});this.selector.renderTo(document.getElementById(e.tagNodeId));return this.selector};MPFEntitySelector.prototype.recalcValue=function(e){if(!BX.type.isArray(e)||!this.inputNode){return}var t=[];e.forEach((function(e){t.push([e.entityId,e.id])}));this.inputNode.value=JSON.stringify(t)};window.MPFEntitySelector=MPFEntitySelector})();
//# sourceMappingURL=script-old.map.js